package com.zss.rocketmq.producer.controller;


import com.zss.rocketmq.producer.common.responseEntity.ResultVO;
import com.zss.rocketmq.producer.service.common.RocketmqProducerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "消息发送测试")
@RestController
@RequestMapping("/mqProducer")
public class MQProducerController {

    public static final Logger logger = LoggerFactory.getLogger(MQProducerController.class);
//    @Value("${rocketmq.producer.topic}")
//    public String topic;
//    @Value("${rocketmq.producer.tag}")
//    public String tag;

    @Autowired
    RocketmqProducerService rocketmqProducerService;

    @ApiOperation(value = "普通消息发送")
    @PostMapping("/send")
    public ResultVO send(String msg,String topic,String tag){
        logger.info("MQProducerController.send|msg:{}",msg);
        ResultVO result = rocketmqProducerService.send(topic, tag, msg);
        return result;
    }
    @ApiOperation(value = "hashKey发送")
    @PostMapping("/sendByHashKey")
    public ResultVO sendByHashKey(String msg,String topic,String tag,String hashKey){
        logger.info("MQProducerController.send|msg:{}",msg);
        ResultVO result = rocketmqProducerService.sendByHashKey(topic, tag,hashKey, msg);
        return result;
    }
    @ApiOperation(value = "顺序发送，指定queue")
    @PostMapping("/sendByOrderly")
    public ResultVO sendByOrderly(String msg,String topic,String tag,String hashKey){
        logger.info("MQProducerController.send|msg:{}",msg);
        ResultVO result = rocketmqProducerService.sendByOrderly(topic, tag,hashKey, msg);
        return result;
    }
}
